<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    /* 滚动条滑动效果 */
    /* html{
      scroll-behavior: smooth;
    } */
    body{
      margin: 0;
    }
    .nav{
      width: 100%;
      height: 80px;
      position: fixed;
      top: -80px;
      left: 0;
      text-align: center;
      line-height: 100px;
      font-size: 30px;
      background-color: pink;
      z-index: 1;
      transition: all .3s;
      
    }
    .content{
      width: 600px;
      height: 1000px;
      margin: 0 auto;
      background-color: green;
      position: relative;
    }
    .tab{
      width: 200px;
      height: 200px;
      background-color: red;
      position: absolute;
      top: 150px;
    }
  </style>
</head>
<body>
  <div>
    <div class="nav">我是顶部导航栏</div>
    <div class="content">
      <div class="tab">
        秒杀
      </div>
    </div>
  </div>
  <script>
    const nav = document.querySelector('.nav')
    const tab = document.querySelector('.tab')
    window.addEventListener('scroll',function(){
      const n = document.documentElement.scrollTop
        // console.log(tab.offsetTop);
        if( n >= tab.offsetTop ){
          nav.style.top = 0 
        }else{
          nav.style.top = '-80px' 
        }
    })
  </script>
</body>
</html>